<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item>
        <el-date-picker
          v-model="dateRange"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"  
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item label="车号" prop="chehao">
        <el-input
          v-model="queryParams.chehao"
          placeholder="请输入车号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="物料名称" prop="wlmc">
        <el-input
          v-model="queryParams.wlmc"
          placeholder="请输入物料名称 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="称重编号" prop="czbh">
        <el-input
          v-model="queryParams.czbh"
          placeholder="请输入称重编号 "
          clearable
          @keyup.enter.native="handleQuery"
<<<<<<< HEAD
        />
=======
        />q
>>>>>>> b4a0e2dba4b1f1e0b05e6d155df4272830d06f27
      </el-form-item>

      <el-form-item label="订单编号" prop="ddbh">
        <el-input
          v-model="queryParams.ddbh"
          placeholder="请输入订单编号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:guozhong:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <!-- v-loading="loading" -->
    <el-table
      v-loading="loading"
      :data="guozhongList"
      @selection-change="handleSelectionChange"
      @row-dblclick="handleDblClick"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="车号" align="center"     prop="chehao" />
      <el-table-column label="称重编号" align="center"  prop="czbh" />
      <el-table-column label="物料名" align="center"    prop="wlmc" />
      <el-table-column label="进厂时间" align="center"  prop="mzsj" />
      <el-table-column label="过磅状态" align="center"  prop="gbzt" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :title="title" :visible.sync="open" width="1300px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px" :inline="true">
  <div>
          <el-form-item label="称重编号" prop="text">
          <el-input v-model="form.czbh" readonly autosize  />
        </el-form-item>
        <el-form-item label="sap单号" prop="text">
          <el-input v-model="form.ddbh" readonly autosize  />
        </el-form-item>
        <el-form-item label="车号" prop="text">
          <el-input v-model="form.chehao" readonly autosize  />
        </el-form-item>
        <el-form-item label="物流名称" prop="text">
          <el-input v-model="form.wlmcc" readonly autosize  />
        </el-form-item>
        </div>
        <div >
          <el-form-item label="供应商名称" prop="text">
          <el-input v-model="form.gysdm" readonly autosize  />
        </el-form-item>
        <el-form-item label="公司名称" prop="text">
          <el-input v-model="form.gsmc" readonly autosize  />
        </el-form-item>
        <el-form-item label="物料名称" prop="text">
          <el-input v-model="form.wlmc" readonly autosize  />
        </el-form-item>
        <el-form-item label="仓库名称" prop="text">
          <el-input v-model="form.ckmc" readonly autosize  />
        </el-form-item>
        </div>
        <div >
          <el-form-item label="送达方" prop="text">
          <el-input v-model="form.songdf" readonly autosize  />
        </el-form-item>
        <el-form-item label="售达方" prop="text">
          <el-input v-model="form.shoudf" readonly autosize  />
        </el-form-item>
        <el-form-item label="毛重" prop="text">
          <el-input v-model="form.mz" readonly autosize  />
        </el-form-item>
        <el-form-item label="毛重时间" prop="text">
          <el-input v-model="form.mzsj" readonly autosize  />
        </el-form-item>
        </div>
        <div >
          <el-form-item label="皮重" prop="text">
          <el-input v-model="form.pz" readonly autosize  />
        </el-form-item>
        <el-form-item label="皮重时间" prop="text">
          <el-input v-model="form.pzsj" readonly autosize  />
        </el-form-item>
        <el-form-item label="净重" prop="text">
          <el-input v-model="form.jz" readonly autosize  />
        </el-form-item>
        <el-form-item label="化验扣重" prop="text">
          <el-input v-model="form.hykz" readonly autosize  />
        </el-form-item>
        </div>
        <div >
          <el-form-item label="化验加罚扣" prop="text">
          <el-input v-model="form.hyjfkx" readonly autosize  />
        </el-form-item>
        <el-form-item label="预置扣重" prop="text">
          <el-input v-model="form.yzkz" readonly autosize  />
        </el-form-item>
        <el-form-item label="预置重量" prop="text">
          <el-input v-model="form.yzzl" readonly autosize  />
        </el-form-item>
        <el-form-item label="结算重量" prop="text">
          <el-input v-model="form.jszl" readonly autosize  />
        </el-form-item>
        </div>
        <div >
          <el-form-item label="结算单价" prop="text">
          <el-input v-model="form.jsdj" readonly autosize  />
        </el-form-item>
        <el-form-item label="结算金额" prop="text">
          <el-input v-model="form.jsje" readonly autosize  />
        </el-form-item>
        <el-form-item label="过磅类型" prop="text">
          <el-input v-model="form.gblx" readonly autosize  />
        </el-form-item>
        <el-form-item label="卸车部门" prop="text">
          <el-input v-model="form.xcbm" readonly autosize  />
        </el-form-item>
        </div>
        <div >
          <el-form-item label="玉米粮食标识" prop="text">
          <el-input v-model="form.zjshbs" readonly autosize  />
        </el-form-item>
        <el-form-item label="订单物料数量" prop="text">
          <el-input v-model="form.ddwlsl" readonly autosize  />
        </el-form-item>
        <el-form-item label="订单原始单号" prop="text">
          <el-input v-model="form.ddysdh" readonly autosize  />
        </el-form-item>
        <el-form-item label="订单原始重量" prop="text">
          <el-input v-model="form.ddyszl" readonly autosize  />
        </el-form-item>
        </div>
        <div >
          <el-form-item label="sap备注1" prop="text">
          <el-input v-model="form.nlmtbz1" readonly autosize  />
        </el-form-item>
        <el-form-item label="sap备注2" prop="text">
          <el-input v-model="form.nlmtbz2" readonly autosize  />
        </el-form-item>
        <el-form-item label="规格" prop="text">
          <el-input v-model="form.guige" readonly autosize  />
        </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
    
    <script>
import {
  listXiangXiInfo,
  listXiangXiAllInfo
} from "@/api/system/Fdongbei/guozhong";

export default {
  name: "Guozhong",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedTbHuayan: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // tb表格数据
      guozhongList: [],
      // 化验--》表格数据
      tbHuayanList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        beginTime: null,
        endTime: null,
        chehao: null,
        wlmc: null,
        czbh: null,
        ddbh: null,
      },
      dateRange: this.timeDefault(),
      dropCar: null,
      selectedValue: null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        beginTime: [{ required: true, message: " 不能为空", trigger: "blur" }],
        endTime: [{ required: true, message: " 不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleDblClick(row, column, event) {
        console.log(row);
        const czbh = row.czbh;
        listXiangXiAllInfo(czbh).then((response)=>{
          this.form = response.data;
        })
        this.open = true;
    },

    // 默认时间
    timeDefault() {
      let date = new Date();

      // 通过时间戳计算
      let defalutStartTime = date.getTime() - 7 * 24 * 3600 * 1000; // 转化为时间戳
      let defalutEndTime = date.getTime();

      let startDateNs = new Date(defalutStartTime);
      let endDateNs = new Date(defalutEndTime);

      // 月，日，时，分，秒 不够10补0
      defalutStartTime =
        startDateNs.getFullYear() +
        "-" +
        (startDateNs.getMonth() + 1 >= 10
          ? startDateNs.getMonth() + 1
          : "0" + (startDateNs.getMonth() + 1)) +
        "-" +
        (startDateNs.getDate() >= 10
          ? startDateNs.getDate()
          : "0" + startDateNs.getDate()) +
        " " +
        (startDateNs.getHours() >= 10
          ? startDateNs.getHours()
          : "0" + startDateNs.getHours()) +
        ":" +
        (startDateNs.getMinutes() >= 10
          ? startDateNs.getMinutes()
          : "0" + startDateNs.getMinutes()) +
        ":" +
        (startDateNs.getSeconds() >= 10
          ? startDateNs.getSeconds()
          : "0" + startDateNs.getSeconds());

      defalutEndTime =
        endDateNs.getFullYear() +
        "-" +
        (endDateNs.getMonth() + 1 >= 10
          ? endDateNs.getMonth() + 1
          : "0" + (endDateNs.getMonth() + 1)) +
        "-" +
        (endDateNs.getDate() >= 10
          ? endDateNs.getDate()
          : "0" + endDateNs.getDate()) +
        " " +
        (endDateNs.getHours() >= 10
          ? endDateNs.getHours()
          : "0" + endDateNs.getHours()) +
        ":" +
        (endDateNs.getMinutes() >= 10
          ? endDateNs.getMinutes()
          : "0" + endDateNs.getMinutes()) +
        ":" +
        (endDateNs.getSeconds() >= 10
          ? endDateNs.getSeconds()
          : "0" + endDateNs.getSeconds());

      return [defalutStartTime, defalutEndTime];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询tb列表 */
    getList() {
      this.loading = true;
      if (this.dateRange.length === 0) {
        this.$alert("请输入要查询的月份！", "提示", {
          confirmButtonText: "确定",
          type: "waring",
        });
      } else {
        this.queryParams.beginTime = this.dateRange[0];
        this.queryParams.endTime = this.dateRange[1];
      }
      if (this.dropCar == true) {
        this.queryParams.yj = "是";
      } else {
        this.queryParams.yj = null;
      }
      this.queryParams.bj = this.selectedValue;
      listXiangXiInfo(this.queryParams).then((response) => {
        this.guozhongList = response.data.list;

        this.total = response.data.total;
        this.loading = false;
      }); 
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        czbh: "",
        chehao: "",
        gysdm: "",
        ckbh: "",
      };
      this.resetForm("form");
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.czbh);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/guozhong/export",
        {
          ...this.queryParams,
        },
        `guozhong_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>